package com.zizy.healthexpert.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.zizy.healthexpert.R;

import java.util.List;

/**
 * Created by Zizy on 2014/5/12.
 */
public class listNutritionAdapter extends ArrayAdapter {
    private Context context = null;
    private int res = 0;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FoodNutrition nutritionResult = (FoodNutrition) getItem(position);//get one item
        ViewGroup viewGroup = (ViewGroup) View.inflate(context, res, null);//inflate
        TextView txtNutritionName=(TextView)viewGroup.findViewById(R.id.txtNutritionName);
        TextView txtUnit=(TextView)viewGroup.findViewById(R.id.txtUnit);
        TextView txtValue=(TextView)viewGroup.findViewById(R.id.txtValue);
        txtNutritionName.setText(nutritionResult.nutritionName);
        txtUnit.setText(String.format("(%s)",nutritionResult.nutritionUnit));
        txtValue.setText(String.valueOf(nutritionResult.nutritionValue));

        return viewGroup;
    }


    public listNutritionAdapter(Context context, int resource, List objects) {
        super(context, resource, objects);
        this.context = context;
        this.res = resource;
    }


    static  public class FoodNutrition {
        String nutritionName;
        double nutritionValue;
        String nutritionUnit;

        /**
         * @param nutritionName     營養素的名字
         * @param nutritionValue    营养素的含量
         * @param nutritionUnit     营养素的單位
         */
        public FoodNutrition(String nutritionName, double nutritionValue, String nutritionUnit) {
            this.nutritionName = nutritionName;
            this.nutritionValue = nutritionValue;
            this.nutritionUnit = nutritionUnit;
        }
    }

}
